s/GtkStyleSet/GtkStyleProperties/
authorCarlos Garnacho <carlosg@gnome.org>
Fri, 29 Oct 2010 04:47:32 +0000 (06:47 +0200)
committerCarlos Garnacho <carlosg@gnome.org>
Sat, 4 Dec 2010 14:38:29 +0000 (15:38 +0100)
The former name had oddities such as gtk_style_set_set() and such,
so the new name is nicer in that regard and not much longer.

13 files changed:
gtk/Makefile.am
gtk/gtk.h
gtk/gtkcssprovider.c
gtk/gtksettings.c
gtk/gtkstylecontext.c
gtk/gtkstyleproperties.c [new file with mode: 0644]
gtk/gtkstyleproperties.h [new file with mode: 0644]
gtk/gtkstyleprovider.c
gtk/gtkstyleprovider.h
gtk/gtkstyleset.c [deleted file]
gtk/gtkstyleset.h [deleted file]
gtk/gtksymboliccolor.c
gtk/gtkthemingengine.c

index a4780a9f1a6abf641314a2ef2010179683bdbe0b..14bde8ccfd522b25881b1169fb9fefde38c95587 100644 (file)
@@ -293,8 +293,8 @@ gtk_public_h_sources =          \
        gtkstatusicon.h         \
        gtkstock.h              \
        gtkstylecontext.h       \
+       gtkstyleproperties.h    \
        gtkstyleprovider.h      \
-       gtkstyleset.h           \
        gtkstyle.h              \
        gtkswitch.h             \
        gtksymboliccolor.h      \
@@ -601,8 +601,8 @@ gtk_base_c_sources =            \
        gtkstatusicon.c         \
        gtkstock.c              \
        gtkstylecontext.c       \
+       gtkstyleproperties.c    \
        gtkstyleprovider.c      \
-       gtkstyleset.c           \
        gtkstyle.c              \
        gtkswitch.c             \
        gtksymboliccolor.c      \
index 92b4c7d21dc285ed2038cb8e26dbee525ceb06c1..36d9a33f047cb071faa74bcf1350f86eb5628230 100644 (file)
--- a/gtk/gtk.h
+++ b/gtk/gtk.h
 #include <gtk/gtkstatusicon.h>
 #include <gtk/gtkstock.h>
 #include <gtk/gtkstylecontext.h>
+#include <gtk/gtkstyleproperties.h>
 #include <gtk/gtkstyleprovider.h>
-#include <gtk/gtkstyleset.h>
 #include <gtk/gtkstyle.h>
 #include <gtk/gtkswitch.h>
 #include <gtk/gtksymboliccolor.h>
index 68cec437df594613a7fee671e50656780d805a44..eaf952c4f2d7e8c9e8f018752f3f515a0b337ed0 100644 (file)
@@ -961,8 +961,8 @@ css_provider_get_selectors (GtkCssProvider *css_provider,
 }
 
 static void
-css_provider_dump_symbolic_colors (GtkCssProvider *css_provider,
-                                   GtkStyleSet    *set)
+css_provider_dump_symbolic_colors (GtkCssProvider     *css_provider,
+                                   GtkStyleProperties *props)
 {
   GtkCssProviderPrivate *priv;
   GHashTableIter iter;
@@ -979,25 +979,25 @@ css_provider_dump_symbolic_colors (GtkCssProvider *css_provider,
       name = key;
       color = value;
 
-      gtk_style_set_map_color (set, name, color);
+      gtk_style_properties_map_color (props, name, color);
     }
 }
 
-static GtkStyleSet *
+static GtkStyleProperties *
 gtk_css_provider_get_style (GtkStyleProvider *provider,
                             GtkWidgetPath    *path)
 {
   GtkCssProvider *css_provider;
   GtkCssProviderPrivate *priv;
-  GtkStyleSet *set;
+  GtkStyleProperties *props;
   GArray *priority_info;
   guint i;
 
   css_provider = GTK_CSS_PROVIDER (provider);
+  props = gtk_style_properties_new ();
   priv = css_provider->priv;
-  set = gtk_style_set_new ();
 
-  css_provider_dump_symbolic_colors (css_provider, set);
+  css_provider_dump_symbolic_colors (css_provider, props);
   priority_info = css_provider_get_selectors (css_provider, path);
 
   for (i = 0; i < priority_info->len; i++)
@@ -1018,16 +1018,16 @@ gtk_css_provider_get_style (GtkStyleProvider *provider,
            * the type is registered or not.
            */
           if (prop[0] == '-' &&
-              !gtk_style_set_lookup_property (prop, NULL, NULL))
+              !gtk_style_properties_lookup_property (prop, NULL, NULL))
             continue;
 
-          gtk_style_set_set_property (set, key, info->state, value);
+          gtk_style_properties_set_property (props, key, info->state, value);
         }
     }
 
   g_array_free (priority_info, TRUE);
 
-  return set;
+  return props;
 }
 
 static gboolean
@@ -2579,7 +2579,7 @@ parse_rule (GtkCssProvider *css_provider,
 
       value_str = g_strstrip (scanner->value.v_identifier);
 
-      if (gtk_style_set_lookup_property (prop, &prop_type, &parse_func))
+      if (gtk_style_properties_lookup_property (prop, &prop_type, &parse_func))
         {
           GValue *val;
 
index d07ce4885b15cc1bd8a7104f64e84ba7f7e1deea..cbfa7a7d8586aa6620600b6a8c01f95cbf0ff27b 100644 (file)
@@ -1253,19 +1253,19 @@ gtk_settings_class_init (GtkSettingsClass *class)
   g_assert (result == PROP_IM_STATUS_STYLE);
 }
 
-static GtkStyleSet *
+static GtkStyleProperties *
 gtk_settings_get_style (GtkStyleProvider *provider,
                         GtkWidgetPath    *path)
 {
   PangoFontDescription *font_desc;
   gchar *font_name, *color_scheme;
   GtkSettings *settings;
-  GtkStyleSet *set;
+  GtkStyleProperties *props;
   gchar **colors;
   guint i;
 
   settings = GTK_SETTINGS (provider);
-  set = gtk_style_set_new ();
+  props = gtk_style_properties_new ();
 
   g_object_get (settings,
                 "gtk-font-name", &font_name,
@@ -1301,22 +1301,22 @@ gtk_settings_get_style (GtkStyleProvider *provider,
         continue;
 
       color = gtk_symbolic_color_new_literal (&col);
-      gtk_style_set_map_color (set, name, color);
+      gtk_style_properties_map_color (props, name, color);
       gtk_symbolic_color_unref (color);
     }
 
   font_desc = pango_font_description_from_string (font_name);
 
-  gtk_style_set_set (set, 0,
-                     "font", font_desc,
-                     NULL);
+  gtk_style_properties_set (props, 0,
+                            "font", font_desc,
+                            NULL);
 
   pango_font_description_free (font_desc);
   g_strfreev (colors);
   g_free (color_scheme);
   g_free (font_name);
 
-  return set;
+  return props;
 }
 
 static void
index 602a83d126393845f3e0c645a06322338d56c2cf..6479c75fe5b1e30f23f671fdd438b27ac2fe9e14 100644 (file)
@@ -226,7 +226,7 @@ struct GtkStyleInfo
 
 struct StyleData
 {
-  GtkStyleSet *store;
+  GtkStyleProperties *store;
   GSList *icon_factories;
   GArray *property_cache;
 };
@@ -438,7 +438,7 @@ style_data_new (void)
   StyleData *data;
 
   data = g_slice_new0 (StyleData);
-  data->store = gtk_style_set_new ();
+  data->store = gtk_style_properties_new ();
 
   return data;
 }
@@ -771,7 +771,7 @@ build_properties (GtkStyleContext *context,
   while ((elem = find_next_candidate (list, global_list)) != NULL)
     {
       GtkStyleProviderData *data;
-      GtkStyleSet *provider_style;
+      GtkStyleProperties *provider_style;
 
       data = elem->data;
 
@@ -784,7 +784,7 @@ build_properties (GtkStyleContext *context,
 
       if (provider_style)
         {
-          gtk_style_set_merge (style_data->store, provider_style, TRUE);
+          gtk_style_properties_merge (style_data->store, provider_style, TRUE);
           g_object_unref (provider_style);
         }
     }
@@ -902,9 +902,9 @@ style_data_lookup (GtkStyleContext *context)
   if (priv->theming_engine)
     g_object_unref (priv->theming_engine);
 
-  gtk_style_set_get (data->store, 0,
-                     "engine", &priv->theming_engine,
-                     NULL);
+  gtk_style_properties_get (data->store, 0,
+                            "engine", &priv->theming_engine,
+                            NULL);
   return data;
 }
 
@@ -1198,7 +1198,7 @@ gtk_style_context_get_property (GtkStyleContext *context,
   g_return_if_fail (priv->widget_path != NULL);
 
   data = style_data_lookup (context);
-  gtk_style_set_get_property (data->store, property, state, value);
+  gtk_style_properties_get_property (data->store, property, state, value);
 }
 
 /**
@@ -1225,7 +1225,7 @@ gtk_style_context_get_valist (GtkStyleContext *context,
   g_return_if_fail (priv->widget_path != NULL);
 
   data = style_data_lookup (context);
-  gtk_style_set_get_valist (data->store, state, args);
+  gtk_style_properties_get_valist (data->store, state, args);
 }
 
 /**
@@ -1256,7 +1256,7 @@ gtk_style_context_get (GtkStyleContext *context,
   data = style_data_lookup (context);
 
   va_start (args, state);
-  gtk_style_set_get_valist (data->store, state, args);
+  gtk_style_properties_get_valist (data->store, state, args);
   va_end (args);
 }
 
@@ -2390,7 +2390,7 @@ gtk_style_context_lookup_color (GtkStyleContext *context,
   g_return_val_if_fail (priv->widget_path != NULL, FALSE);
 
   data = style_data_lookup (context);
-  sym_color = gtk_style_set_lookup_color (data->store, color_name);
+  sym_color = gtk_style_properties_lookup_color (data->store, color_name);
 
   if (!sym_color)
     return FALSE;
@@ -2497,9 +2497,9 @@ gtk_style_context_notify_state_change (GtkStyleContext *context,
    * state, it will fallback to the normal state as well if necessary.
    */
   data = style_data_lookup (context);
-  gtk_style_set_get (data->store, flags,
-                     "transition", &desc,
-                     NULL);
+  gtk_style_properties_get (data->store, flags,
+                            "transition", &desc,
+                            NULL);
 
   if (!desc)
     return;
diff --git a/gtk/gtkstyleproperties.c b/gtk/gtkstyleproperties.c
new file mode 100644 (file)
index 0000000..df8529b
--- /dev/null
@@ -0,0 +1,1076 @@
+/* GTK - The GIMP Toolkit
+ * Copyright (C) 2010 Carlos Garnacho <carlosg@gnome.org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#include "config.h"
+
+#include <stdlib.h>
+#include <gobject/gvaluecollector.h>
+#include <cairo/cairo-gobject.h>
+
+#include "gtktypebuiltins.h"
+#include "gtkstyleprovider.h"
+#include "gtkstyleproperties.h"
+#include "gtkprivate.h"
+#include "gtkthemingengine.h"
+#include "gtkanimationdescription.h"
+#include "gtk9slice.h"
+#include "gtkintl.h"
+
+typedef struct GtkStylePropertiesPrivate GtkStylePropertiesPrivate;
+typedef struct PropertyData PropertyData;
+typedef struct PropertyNode PropertyNode;
+typedef struct ValueData ValueData;
+
+struct PropertyNode
+{
+  GQuark property_quark;
+  GType property_type;
+  GValue default_value;
+  GtkStylePropertyParser parse_func;
+};
+
+struct ValueData
+{
+  GtkStateFlags state;
+  GValue value;
+};
+
+struct PropertyData
+{
+  GArray *values;
+};
+
+struct GtkStylePropertiesPrivate
+{
+  GHashTable *color_map;
+  GHashTable *properties;
+};
+
+static GArray *properties = NULL;
+
+static void gtk_style_properties_provider_init (GtkStyleProviderIface *iface);
+static void gtk_style_properties_finalize      (GObject      *object);
+
+
+G_DEFINE_TYPE_EXTENDED (GtkStyleProperties, gtk_style_properties, G_TYPE_OBJECT, 0,
+                        G_IMPLEMENT_INTERFACE (GTK_TYPE_STYLE_PROVIDER,
+                                               gtk_style_properties_provider_init));
+
+static void
+gtk_style_properties_class_init (GtkStylePropertiesClass *klass)
+{
+  GObjectClass *object_class = G_OBJECT_CLASS (klass);
+  GValue val = { 0 };
+
+  object_class->finalize = gtk_style_properties_finalize;
+
+  /* Initialize default property set */
+  gtk_style_properties_register_property ("color", GDK_TYPE_RGBA, NULL, NULL);
+  gtk_style_properties_register_property ("background-color", GDK_TYPE_RGBA, NULL, NULL);
+
+  gtk_style_properties_register_property ("font", PANGO_TYPE_FONT_DESCRIPTION, NULL, NULL);
+
+  gtk_style_properties_register_property ("margin", GTK_TYPE_BORDER, NULL, NULL);
+  gtk_style_properties_register_property ("padding", GTK_TYPE_BORDER, NULL, NULL);
+
+  gtk_style_properties_register_property ("border-width", G_TYPE_INT, NULL, NULL);
+  gtk_style_properties_register_property ("border-radius", G_TYPE_INT, NULL, NULL);
+  gtk_style_properties_register_property ("border-style", GTK_TYPE_BORDER_STYLE, NULL, NULL);
+  gtk_style_properties_register_property ("border-color", GDK_TYPE_RGBA, NULL, NULL);
+
+  gtk_style_properties_register_property ("background-image", CAIRO_GOBJECT_TYPE_PATTERN, NULL, NULL);
+  gtk_style_properties_register_property ("border-image", GTK_TYPE_9SLICE, NULL, NULL);
+
+  g_value_init (&val, GTK_TYPE_THEMING_ENGINE);
+  g_value_set_object (&val, (GObject *) gtk_theming_engine_load (NULL));
+  gtk_style_properties_register_property ("engine", GTK_TYPE_THEMING_ENGINE, &val, NULL);
+  g_value_unset (&val);
+
+  g_value_init (&val, GTK_TYPE_ANIMATION_DESCRIPTION);
+  g_value_take_boxed (&val, gtk_animation_description_new (0, GTK_TIMELINE_PROGRESS_LINEAR));
+  gtk_style_properties_register_property ("transition", GTK_TYPE_ANIMATION_DESCRIPTION, &val, NULL);
+  g_value_unset (&val);
+
+  g_type_class_add_private (object_class, sizeof (GtkStylePropertiesPrivate));
+}
+
+static PropertyData *
+property_data_new (void)
+{
+  PropertyData *data;
+
+  data = g_slice_new0 (PropertyData);
+  data->values = g_array_new (FALSE, FALSE, sizeof (ValueData));
+
+  return data;
+}
+
+static void
+property_data_free (PropertyData *data)
+{
+  guint i;
+
+  for (i = 0; i < data->values->len; i++)
+    {
+      ValueData *value_data;
+
+      value_data = &g_array_index (data->values, ValueData, i);
+
+      if (G_IS_VALUE (&value_data->value))
+        g_value_unset (&value_data->value);
+    }
+
+  g_array_free (data->values, TRUE);
+  g_slice_free (PropertyData, data);
+}
+
+static gboolean
+property_data_find_position (PropertyData  *data,
+                             GtkStateFlags  state,
+                             guint         *pos)
+{
+  gint min, max, mid;
+  gboolean found = FALSE;
+  guint position;
+
+  if (pos)
+    *pos = 0;
+
+  if (data->values->len == 0)
+    return FALSE;
+
+  /* Find position for the given state, or the position where
+   * it would be if not found, the array is ordered by the
+   * state flags.
+   */
+  min = 0;
+  max = data->values->len - 1;
+
+  do
+    {
+      ValueData *value_data;
+
+      mid = (min + max) / 2;
+      value_data = &g_array_index (data->values, ValueData, mid);
+
+      if (value_data->state == state)
+        {
+          found = TRUE;
+          position = mid;
+        }
+      else if (value_data->state < state)
+          position = min = mid + 1;
+      else
+        {
+          max = mid - 1;
+          position = mid;
+        }
+    }
+  while (!found && min <= max);
+
+  if (pos)
+    *pos = position;
+
+  return found;
+}
+
+static GValue *
+property_data_get_value (PropertyData  *data,
+                         GtkStateFlags  state)
+{
+  ValueData *val_data;
+  guint pos;
+
+  if (!property_data_find_position (data, state, &pos))
+    {
+      ValueData new = { 0 };
+
+      //val_data = &g_array_index (data->values, ValueData, pos);
+      new.state = state;
+      g_array_insert_val (data->values, pos, new);
+    }
+
+  val_data = &g_array_index (data->values, ValueData, pos);
+
+  return &val_data->value;
+}
+
+static GValue *
+property_data_match_state (PropertyData  *data,
+                           GtkStateFlags  state)
+{
+  guint pos;
+  gint i;
+
+  if (property_data_find_position (data, state, &pos))
+    {
+      ValueData *val_data;
+
+      /* Exact match */
+      val_data = &g_array_index (data->values, ValueData, pos);
+      return &val_data->value;
+    }
+
+  if (pos >= data->values->len)
+    pos = data->values->len - 1;
+
+  /* No exact match, go downwards the list to find
+   * the closest match to the given state flags, as
+   * a side effect, there is an implicit precedence
+   * of higher flags over the smaller ones.
+   */
+  for (i = pos; i >= 0; i--)
+    {
+      ValueData *val_data;
+
+      val_data = &g_array_index (data->values, ValueData, i);
+
+       /* Check whether any of the requested
+        * flags are set, and no other flags are.
+        *
+        * Also, no flags acts as a wildcard, such
+        * value should be always in the first position
+        * in the array (if present) anyways.
+        */
+      if (val_data->state == 0 ||
+          ((val_data->state & state) != 0 &&
+           (val_data->state & ~state) == 0))
+        return &val_data->value;
+    }
+
+  return NULL;
+}
+
+static void
+gtk_style_properties_init (GtkStyleProperties *props)
+{
+  GtkStylePropertiesPrivate *priv;
+
+  priv = props->priv = G_TYPE_INSTANCE_GET_PRIVATE (props,
+                                                    GTK_TYPE_STYLE_PROPERTIES,
+                                                    GtkStylePropertiesPrivate);
+
+  priv->properties = g_hash_table_new_full (NULL, NULL, NULL,
+                                            (GDestroyNotify) property_data_free);
+}
+
+static void
+gtk_style_properties_finalize (GObject *object)
+{
+  GtkStylePropertiesPrivate *priv;
+  GtkStyleProperties *props;
+
+  props = GTK_STYLE_PROPERTIES (object);
+  priv = props->priv;
+  g_hash_table_destroy (priv->properties);
+
+  if (priv->color_map)
+    g_hash_table_destroy (priv->color_map);
+
+  G_OBJECT_CLASS (gtk_style_properties_parent_class)->finalize (object);
+}
+
+GtkStyleProperties *
+gtk_style_properties_get_style (GtkStyleProvider *provider,
+                                GtkWidgetPath    *path)
+{
+  /* Return style set itself */
+  return g_object_ref (provider);
+}
+
+static void
+gtk_style_properties_provider_init (GtkStyleProviderIface *iface)
+{
+  iface->get_style = gtk_style_properties_get_style;
+}
+
+static int
+compare_property (gconstpointer p1,
+                  gconstpointer p2)
+{
+  PropertyNode *key = (PropertyNode *) p1;
+  PropertyNode *node = (PropertyNode *) p2;
+
+  if (key->property_quark > node->property_quark)
+    return 1;
+  else if (key->property_quark < node->property_quark)
+    return -1;
+
+  return 0;
+}
+
+static PropertyNode *
+property_node_lookup (GQuark quark)
+{
+  PropertyNode key = { 0 };
+
+  if (!quark)
+    return NULL;
+
+  if (!properties)
+    return NULL;
+
+  key.property_quark = quark;
+
+  return bsearch (&key, properties->data, properties->len,
+                  sizeof (PropertyNode), compare_property);
+}
+
+/* Property registration functions */
+
+/**
+ * gtk_style_properties_register_property:
+ * @property_name: property name to register
+ * @type: #GType the property will hold
+ * @default_value: default value for this property
+ * @parse_func: parsing function to use, or %NULL
+ *
+ * Registers a property so it can be used in the CSS file format.
+ * This function is the low-level equivalent of
+ * gtk_theming_engine_register_property(), if you are implementing
+ * a theming engine, you want to use that function instead.
+ *
+ * Since: 3.0
+ **/
+void
+gtk_style_properties_register_property (const gchar            *property_name,
+                                        GType                   type,
+                                        const GValue           *default_value,
+                                        GtkStylePropertyParser  parse_func)
+{
+  PropertyNode *node, new = { 0 };
+  GQuark quark;
+  gint i;
+
+  g_return_if_fail (property_name != NULL);
+  g_return_if_fail (type != 0);
+
+  if (G_UNLIKELY (!properties))
+    properties = g_array_new (FALSE, TRUE, sizeof (PropertyNode));
+
+  quark = g_quark_try_string (property_name);
+
+  if ((node = property_node_lookup (quark)) != NULL)
+    {
+      g_warning ("Property \"%s\" was already registered with type %s",
+                 property_name, g_type_name (node->property_type));
+      return;
+    }
+
+  quark = g_quark_from_string (property_name);
+
+  new.property_quark = quark;
+  new.property_type = type;
+
+  if (default_value)
+    {
+      g_value_init (&new.default_value, G_VALUE_TYPE (default_value));
+      g_value_copy (default_value, &new.default_value);
+    }
+  else
+    g_value_init (&new.default_value, type);
+
+  if (parse_func)
+    new.parse_func = parse_func;
+
+  for (i = 0; i < properties->len; i++)
+    {
+      node = &g_array_index (properties, PropertyNode, i);
+
+      if (node->property_quark > quark)
+        break;
+    }
+
+  g_array_insert_val (properties, i, new);
+}
+
+/**
+ * gtk_style_properties_lookup_property:
+ * @property_name: property name to look up
+ * @type: (out): return location for the looked up property type
+ * @parse_func: (out): return value for the parse function
+ *
+ * Returns %TRUE if a property has been registered, if @type or
+ * @parse_func are not %NULL, the property #GType and parsing function
+ * will be respectively returned.
+ *
+ * Returns: %TRUE if the property is registered, %FALSE otherwise
+ *
+ * Since: 3.0
+ **/
+gboolean
+gtk_style_properties_lookup_property (const gchar            *property_name,
+                                      GType                  *type,
+                                      GtkStylePropertyParser *parse_func)
+{
+  PropertyNode *node;
+  GtkStylePropertiesClass *klass;
+  gboolean found = FALSE;
+  GQuark quark;
+  gint i;
+
+  g_return_val_if_fail (property_name != NULL, FALSE);
+
+  klass = g_type_class_ref (GTK_TYPE_STYLE_PROPERTIES);
+  quark = g_quark_try_string (property_name);
+
+  if (quark == 0)
+    {
+      g_type_class_unref (klass);
+      return FALSE;
+    }
+
+  for (i = 0; i < properties->len; i++)
+    {
+      node = &g_array_index (properties, PropertyNode, i);
+
+      if (node->property_quark == quark)
+        {
+          if (type)
+            *type = node->property_type;
+
+          if (parse_func)
+            *parse_func = node->parse_func;
+
+          found = TRUE;
+          break;
+        }
+      else if (node->property_quark > quark)
+        break;
+    }
+
+  g_type_class_unref (klass);
+
+  return found;
+}
+
+/* GtkStyleProperties methods */
+
+/**
+ * gtk_style_properties_new:
+ *
+ * Returns a newly created #GtkStyleProperties
+ *
+ * Returns: a new #GtkStyleProperties
+ **/
+GtkStyleProperties *
+gtk_style_properties_new (void)
+{
+  return g_object_new (GTK_TYPE_STYLE_PROPERTIES, NULL);
+}
+
+/**
+ * gtk_style_properties_map_color:
+ * @props: a #GtkStyleProperties
+ * @name: color name
+ * @color: #GtkSymbolicColor to map @name to
+ *
+ * Maps @color so it can be referenced by @name. See
+ * gtk_style_properties_lookup_color()
+ *
+ * Since: 3.0
+ **/
+void
+gtk_style_properties_map_color (GtkStyleProperties *props,
+                                const gchar        *name,
+                                GtkSymbolicColor   *color)
+{
+  GtkStylePropertiesPrivate *priv;
+
+  g_return_if_fail (GTK_IS_STYLE_PROPERTIES (props));
+  g_return_if_fail (name != NULL);
+  g_return_if_fail (color != NULL);
+
+  priv = props->priv;
+
+  if (G_UNLIKELY (!priv->color_map))
+    priv->color_map = g_hash_table_new_full (g_str_hash,
+                                             g_str_equal,
+                                             (GDestroyNotify) g_free,
+                                             (GDestroyNotify) gtk_symbolic_color_unref);
+
+  g_hash_table_replace (priv->color_map,
+                        g_strdup (name),
+                        gtk_symbolic_color_ref (color));
+}
+
+/**
+ * gtk_style_properties_lookup_color:
+ * @props: a #GtkStyleProperties
+ * @name: color name to lookup
+ *
+ * Returns the symbolic color that is mapped
+ * to @name.
+ *
+ * Returns: The mapped color
+ *
+ * Since: 3.0
+ **/
+GtkSymbolicColor *
+gtk_style_properties_lookup_color (GtkStyleProperties *props,
+                                   const gchar        *name)
+{
+  GtkStylePropertiesPrivate *priv;
+
+  g_return_val_if_fail (GTK_IS_STYLE_PROPERTIES (props), NULL);
+  g_return_val_if_fail (name != NULL, NULL);
+
+  priv = props->priv;
+
+  if (!priv->color_map)
+    return NULL;
+
+  return g_hash_table_lookup (priv->color_map, name);
+}
+
+/**
+ * gtk_style_properties_set_property:
+ * @props: a #GtkStyleProperties
+ * @property: styling property to set
+ * @state: state to set the value for
+ * @value: new value for the property
+ *
+ * Sets a styling property in @props.
+ *
+ * Since: 3.0
+ **/
+void
+gtk_style_properties_set_property (GtkStyleProperties *props,
+                                   const gchar        *property,
+                                   GtkStateFlags       state,
+                                   const GValue       *value)
+{
+  GtkStylePropertiesPrivate *priv;
+  PropertyNode *node;
+  PropertyData *prop;
+  GType value_type;
+  GValue *val;
+
+  g_return_if_fail (GTK_IS_STYLE_PROPERTIES (props));
+  g_return_if_fail (property != NULL);
+  g_return_if_fail (value != NULL);
+
+  value_type = G_VALUE_TYPE (value);
+  node = property_node_lookup (g_quark_try_string (property));
+
+  if (!node)
+    {
+      g_warning ("Style property \"%s\" is not registered", property);
+      return;
+    }
+
+  if (node->property_type == GDK_TYPE_RGBA)
+    {
+      /* Allow GtkSymbolicColor as well */
+      g_return_if_fail (value_type == GDK_TYPE_RGBA || value_type == GTK_TYPE_SYMBOLIC_COLOR);
+    }
+  else if (node->property_type == CAIRO_GOBJECT_TYPE_PATTERN)
+    {
+      /* Allow GtkGradient as a substitute */
+      g_return_if_fail (value_type == CAIRO_GOBJECT_TYPE_PATTERN ||
+                        value_type == GTK_TYPE_GRADIENT);
+    }
+  else
+    g_return_if_fail (node->property_type == value_type);
+
+  priv = props->priv;
+  prop = g_hash_table_lookup (priv->properties,
+                              GINT_TO_POINTER (node->property_quark));
+
+  if (!prop)
+    {
+      prop = property_data_new ();
+      g_hash_table_insert (priv->properties,
+                           GINT_TO_POINTER (node->property_quark),
+                           prop);
+    }
+
+  val = property_data_get_value (prop, state);
+
+  if (G_VALUE_TYPE (val) == value_type)
+    g_value_reset (val);
+  else
+    {
+      if (G_IS_VALUE (val))
+        g_value_unset (val);
+
+      g_value_init (val, value_type);
+    }
+
+  g_value_copy (value, val);
+}
+
+/**
+ * gtk_style_properties_set_valist:
+ * @props: a #GtkStyleProperties
+ * @state: state to set the values for
+ * @args: va_list of property name/value pairs, followed by %NULL
+ *
+ * Sets several style properties on @props.
+ *
+ * Since: 3.0
+ **/
+void
+gtk_style_properties_set_valist (GtkStyleProperties *props,
+                                 GtkStateFlags       state,
+                                 va_list             args)
+{
+  GtkStylePropertiesPrivate *priv;
+  const gchar *property_name;
+
+  g_return_if_fail (GTK_IS_STYLE_PROPERTIES (props));
+
+  priv = props->priv;
+  property_name = va_arg (args, const gchar *);
+
+  while (property_name)
+    {
+      PropertyNode *node;
+      PropertyData *prop;
+      gchar *error = NULL;
+      GValue *val;
+
+      node = property_node_lookup (g_quark_try_string (property_name));
+
+      if (!node)
+        {
+          g_warning ("Style property \"%s\" is not registered", property_name);
+          break;
+        }
+
+      prop = g_hash_table_lookup (priv->properties,
+                                  GINT_TO_POINTER (node->property_quark));
+
+      if (!prop)
+        {
+          prop = property_data_new ();
+          g_hash_table_insert (priv->properties,
+                               GINT_TO_POINTER (node->property_quark),
+                               prop);
+        }
+
+      val = property_data_get_value (prop, state);
+
+      if (G_IS_VALUE (val))
+        g_value_unset (val);
+
+      g_value_init (val, node->property_type);
+      G_VALUE_COLLECT (val, args, 0, &error);
+
+      if (error)
+        {
+          g_warning ("Could not set style property \"%s\": %s", property_name, error);
+          g_value_unset (val);
+          g_free (error);
+          break;
+        }
+
+      property_name = va_arg (args, const gchar *);
+    }
+}
+
+/**
+ * gtk_style_properties_set:
+ * @props: a #GtkStyleProperties
+ * @state: state to set the values for
+ * @...: property name/value pairs, followed by %NULL
+ *
+ * Sets several style properties on @props.
+ *
+ * Since: 3.0
+ **/
+void
+gtk_style_properties_set (GtkStyleProperties *props,
+                          GtkStateFlags       state,
+                          ...)
+{
+  va_list args;
+
+  g_return_if_fail (GTK_IS_STYLE_PROPERTIES (props));
+
+  va_start (args, state);
+  gtk_style_properties_set_valist (props, state, args);
+  va_end (args);
+}
+
+static gboolean
+resolve_color (GtkStyleProperties *props,
+              GValue             *value)
+{
+  GdkRGBA color;
+
+  /* Resolve symbolic color to GdkRGBA */
+  if (!gtk_symbolic_color_resolve (g_value_get_boxed (value), props, &color))
+    return FALSE;
+
+  /* Store it back, this is where GdkRGBA caching happens */
+  g_value_unset (value);
+  g_value_init (value, GDK_TYPE_RGBA);
+  g_value_set_boxed (value, &color);
+
+  return TRUE;
+}
+
+static gboolean
+resolve_gradient (GtkStyleProperties *props,
+                  GValue             *value)
+{
+  cairo_pattern_t *gradient;
+
+  if (!gtk_gradient_resolve (g_value_get_boxed (value), props, &gradient))
+    return FALSE;
+
+  /* Store it back, this is where cairo_pattern_t caching happens */
+  g_value_unset (value);
+  g_value_init (value, CAIRO_GOBJECT_TYPE_PATTERN);
+  g_value_take_boxed (value, gradient);
+
+  return TRUE;
+}
+
+/**
+ * gtk_style_properties_get_property:
+ * @props: a #GtkStyleProperties
+ * @property: style property name
+ * @state: state to retrieve the property value for
+ * @value: (out) (transfer full):  return location for the style property value.
+ *
+ * Gets a style property from @props for the given state. When done with @value,
+ * g_value_unset() needs to be called to free any allocated memory.
+ *
+ * Returns: %TRUE if the property exists in @props, %FALSE otherwise
+ *
+ * Since: 3.0
+ **/
+gboolean
+gtk_style_properties_get_property (GtkStyleProperties *props,
+                                   const gchar        *property,
+                                   GtkStateFlags       state,
+                                   GValue             *value)
+{
+  GtkStylePropertiesPrivate *priv;
+  PropertyNode *node;
+  PropertyData *prop;
+  GValue *val;
+
+  g_return_val_if_fail (GTK_IS_STYLE_PROPERTIES (props), FALSE);
+  g_return_val_if_fail (property != NULL, FALSE);
+  g_return_val_if_fail (value != NULL, FALSE);
+
+  node = property_node_lookup (g_quark_try_string (property));
+
+  if (!node)
+    {
+      g_warning ("Style property \"%s\" is not registered", property);
+      return FALSE;
+    }
+
+  priv = props->priv;
+  prop = g_hash_table_lookup (priv->properties,
+                              GINT_TO_POINTER (node->property_quark));
+
+  if (!prop)
+    return FALSE;
+
+  g_value_init (value, node->property_type);
+
+  val = property_data_match_state (prop, state);
+
+  if (!val)
+    val = &node->default_value;
+
+  g_return_val_if_fail (G_IS_VALUE (val), FALSE);
+
+  if (G_VALUE_TYPE (val) == GTK_TYPE_SYMBOLIC_COLOR)
+    {
+      g_return_val_if_fail (node->property_type == GDK_TYPE_RGBA, FALSE);
+
+      if (!resolve_color (props, val))
+        return FALSE;
+    }
+  else if (G_VALUE_TYPE (val) == GTK_TYPE_GRADIENT)
+    {
+      g_return_val_if_fail (node->property_type == CAIRO_GOBJECT_TYPE_PATTERN, FALSE);
+
+      if (!resolve_gradient (props, val))
+        return FALSE;
+    }
+
+  g_value_copy (val, value);
+
+  return TRUE;
+}
+
+/**
+ * gtk_style_properties_get_valist:
+ * @props: a #GtkStyleProperties
+ * @state: state to retrieve the property values for
+ * @args: va_list of property name/return location pairs, followed by %NULL
+ *
+ * Retrieves several style property values from @props for a given state.
+ *
+ * Since: 3.0
+ **/
+void
+gtk_style_properties_get_valist (GtkStyleProperties *props,
+                                 GtkStateFlags       state,
+                                 va_list             args)
+{
+  GtkStylePropertiesPrivate *priv;
+  const gchar *property_name;
+
+  g_return_if_fail (GTK_IS_STYLE_PROPERTIES (props));
+
+  priv = props->priv;
+  property_name = va_arg (args, const gchar *);
+
+  while (property_name)
+    {
+      PropertyNode *node;
+      PropertyData *prop;
+      gchar *error = NULL;
+      GValue *val = NULL;
+
+      node = property_node_lookup (g_quark_try_string (property_name));
+
+      if (!node)
+        {
+          g_warning ("Style property \"%s\" is not registered", property_name);
+          break;
+        }
+
+      prop = g_hash_table_lookup (priv->properties,
+                                  GINT_TO_POINTER (node->property_quark));
+
+      if (prop)
+        val = property_data_match_state (prop, state);
+
+      if (!val)
+        val = &node->default_value;
+
+      if (G_VALUE_TYPE (val) == GTK_TYPE_SYMBOLIC_COLOR)
+        {
+          g_return_if_fail (node->property_type == GDK_TYPE_RGBA);
+
+          if (!resolve_color (props, val))
+            val = &node->default_value;
+        }
+      else if (G_VALUE_TYPE (val) == GTK_TYPE_GRADIENT)
+        {
+          g_return_if_fail (node->property_type == CAIRO_GOBJECT_TYPE_PATTERN);
+
+          if (!resolve_gradient (props, val))
+            val = &node->default_value;
+        }
+
+      G_VALUE_LCOPY (val, args, 0, &error);
+
+      if (error)
+        {
+          g_warning ("Could not get style property \"%s\": %s", property_name, error);
+          g_free (error);
+          break;
+        }
+
+      property_name = va_arg (args, const gchar *);
+    }
+}
+
+/**
+ * gtk_style_properties_get:
+ * @props: a #GtkStyleProperties
+ * @state: state to retrieve the property values for
+ * @...: property name /return value pairs, followed by %NULL
+ *
+ * Retrieves several style property values from @props for a
+ * given state.
+ *
+ * Since: 3.0
+ **/
+void
+gtk_style_properties_get (GtkStyleProperties *props,
+                          GtkStateFlags       state,
+                          ...)
+{
+  va_list args;
+
+  g_return_if_fail (GTK_IS_STYLE_PROPERTIES (props));
+
+  va_start (args, state);
+  gtk_style_properties_get_valist (props, state, args);
+  va_end (args);
+}
+
+/**
+ * gtk_style_properties_unset_property:
+ * @props: a #GtkStyleProperties
+ * @property: property to unset
+ * @state: state to unset
+ *
+ * Unsets a style property in @props.
+ *
+ * Since: 3.0
+ **/
+void
+gtk_style_properties_unset_property (GtkStyleProperties *props,
+                                     const gchar        *property,
+                                     GtkStateFlags       state)
+{
+  GtkStylePropertiesPrivate *priv;
+  PropertyNode *node;
+  PropertyData *prop;
+  guint pos;
+
+  g_return_if_fail (GTK_IS_STYLE_PROPERTIES (props));
+  g_return_if_fail (property != NULL);
+
+  node = property_node_lookup (g_quark_try_string (property));
+
+  if (!node)
+    {
+      g_warning ("Style property \"%s\" is not registered", property);
+      return;
+    }
+
+  priv = props->priv;
+  prop = g_hash_table_lookup (priv->properties,
+                              GINT_TO_POINTER (node->property_quark));
+
+  if (!prop)
+    return;
+
+  if (property_data_find_position (prop, state, &pos))
+    {
+      ValueData *data;
+
+      data = &g_array_index (prop->values, ValueData, pos);
+
+      if (G_IS_VALUE (&data->value))
+        g_value_unset (&data->value);
+
+      g_array_remove_index (prop->values, pos);
+    }
+}
+
+/**
+ * gtk_style_properties_clear:
+ * @props: a #GtkStyleProperties
+ *
+ * Clears all style information from @props.
+ **/
+void
+gtk_style_properties_clear (GtkStyleProperties *props)
+{
+  GtkStylePropertiesPrivate *priv;
+
+  g_return_if_fail (GTK_IS_STYLE_PROPERTIES (props));
+
+  priv = props->priv;
+  g_hash_table_remove_all (priv->properties);
+}
+
+/**
+ * gtk_style_properties_merge:
+ * @props: a #GtkStyleProperties
+ * @props_to_merge: a second #GtkStyleProperties
+ * @replace: whether to replace values or not
+ *
+ * Merges into @props all the style information contained
+ * in @props_to_merge. If @replace is %TRUE, the values
+ * will be overwritten, if it is %FALSE, the older values
+ * will prevail.
+ *
+ * Since: 3.0
+ **/
+void
+gtk_style_properties_merge (GtkStyleProperties       *props,
+                            const GtkStyleProperties *props_to_merge,
+                            gboolean                  replace)
+{
+  GtkStylePropertiesPrivate *priv, *priv_to_merge;
+  GHashTableIter iter;
+  gpointer key, value;
+
+  g_return_if_fail (GTK_IS_STYLE_PROPERTIES (props));
+  g_return_if_fail (GTK_IS_STYLE_PROPERTIES (props_to_merge));
+
+  priv = props->priv;
+  priv_to_merge = props_to_merge->priv;
+
+  /* Merge symbolic color map */
+  if (priv_to_merge->color_map)
+    {
+      g_hash_table_iter_init (&iter, priv_to_merge->color_map);
+
+      while (g_hash_table_iter_next (&iter, &key, &value))
+        {
+          const gchar *name;
+          GtkSymbolicColor *color;
+
+          name = key;
+          color = value;
+
+          if (!replace &&
+              g_hash_table_lookup (priv->color_map, name))
+            continue;
+
+          gtk_style_properties_map_color (props, name, color);
+        }
+    }
+
+  /* Merge symbolic style properties */
+  g_hash_table_iter_init (&iter, priv_to_merge->properties);
+
+  while (g_hash_table_iter_next (&iter, &key, &value))
+    {
+      PropertyData *prop_to_merge = value;
+      PropertyData *prop;
+      guint i;
+
+      prop = g_hash_table_lookup (priv->properties, key);
+
+      if (!prop)
+        {
+          prop = property_data_new ();
+          g_hash_table_insert (priv->properties, key, prop);
+        }
+
+      for (i = 0; i < prop_to_merge->values->len; i++)
+        {
+          ValueData *data;
+          GValue *value;
+
+          data = &g_array_index (prop_to_merge->values, ValueData, i);
+          value = property_data_get_value (prop, data->state);
+
+          if (replace || !G_IS_VALUE (value))
+            {
+              if (!G_IS_VALUE (value))
+                g_value_init (value, G_VALUE_TYPE (&data->value));
+              else if (G_VALUE_TYPE (value) != G_VALUE_TYPE (&data->value))
+                {
+                  g_value_unset (value);
+                  g_value_init (value, G_VALUE_TYPE (&data->value));
+                }
+
+              g_value_copy (&data->value, value);
+            }
+        }
+    }
+}
diff --git a/gtk/gtkstyleproperties.h b/gtk/gtkstyleproperties.h
new file mode 100644 (file)
index 0000000..b12c223
--- /dev/null
@@ -0,0 +1,115 @@
+/* GTK - The GIMP Toolkit
+ * Copyright (C) 2010 Carlos Garnacho <carlosg@gnome.org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#ifndef __GTK_STYLE_PROPERTIES_H__
+#define __GTK_STYLE_PROPERTIES_H__
+
+#include <glib-object.h>
+#include <gdk/gdk.h>
+#include "gtkenums.h"
+#include "gtksymboliccolor.h"
+
+G_BEGIN_DECLS
+
+#define GTK_TYPE_STYLE_PROPERTIES         (gtk_style_properties_get_type ())
+#define GTK_STYLE_PROPERTIES(o)           (G_TYPE_CHECK_INSTANCE_CAST ((o), GTK_TYPE_STYLE_PROPERTIES, GtkStyleProperties))
+#define GTK_STYLE_PROPERTIES_CLASS(c)     (G_TYPE_CHECK_CLASS_CAST    ((c), GTK_TYPE_STYLE_PROPERTIES, GtkStylePropertiesClass))
+#define GTK_IS_STYLE_PROPERTIES(o)        (G_TYPE_CHECK_INSTANCE_TYPE ((o), GTK_TYPE_STYLE_PROPERTIES))
+#define GTK_IS_STYLE_PROPERTIES_CLASS(c)  (G_TYPE_CHECK_CLASS_TYPE    ((c), GTK_TYPE_STYLE_PROPERTIES))
+#define GTK_STYLE_PROPERTIES_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS  ((o), GTK_TYPE_STYLE_PROPERTIES, GtkStylePropertiesClass))
+
+typedef struct _GtkStyleProperties GtkStyleProperties;
+typedef struct _GtkStylePropertiesClass GtkStylePropertiesClass;
+
+struct _GtkStyleProperties
+{
+  GObject parent_object;
+  gpointer priv;
+};
+
+struct _GtkStylePropertiesClass
+{
+  GObjectClass parent_class;
+};
+
+typedef gboolean (* GtkStylePropertyParser) (const gchar  *string,
+                                             GValue       *value,
+                                             GError      **error);
+
+GType gtk_style_properties_get_type (void) G_GNUC_CONST;
+
+/* Functions to register style properties */
+void     gtk_style_properties_register_property (const gchar            *property_name,
+                                                 GType                   type,
+                                                 const GValue           *default_value,
+                                                 GtkStylePropertyParser  parse_func);
+gboolean gtk_style_properties_lookup_property   (const gchar            *property_name,
+                                                 GType                  *type,
+                                                 GtkStylePropertyParser *parse_func);
+
+GtkStyleProperties * gtk_style_properties_new (void);
+
+void               gtk_style_properties_map_color    (GtkStyleProperties *props,
+                                                      const gchar        *name,
+                                                      GtkSymbolicColor   *color);
+GtkSymbolicColor * gtk_style_properties_lookup_color (GtkStyleProperties *set,
+                                                      const gchar        *name);
+
+void     gtk_style_properties_set_property (GtkStyleProperties *props,
+                                            const gchar        *property,
+                                            GtkStateFlags       state,
+                                            const GValue       *value);
+void     gtk_style_properties_set_valist   (GtkStyleProperties *props,
+                                            GtkStateFlags       state,
+                                            va_list             args);
+void     gtk_style_properties_set          (GtkStyleProperties *props,
+                                            GtkStateFlags       state,
+                                            ...) G_GNUC_NULL_TERMINATED;
+
+gboolean gtk_style_properties_get_property (GtkStyleProperties *props,
+                                            const gchar        *property,
+                                            GtkStateFlags       state,
+                                            GValue             *value);
+void     gtk_style_properties_get_valist   (GtkStyleProperties *props,
+                                            GtkStateFlags       state,
+                                            va_list             args);
+void     gtk_style_properties_get          (GtkStyleProperties *props,
+                                            GtkStateFlags       state,
+                                            ...) G_GNUC_NULL_TERMINATED;
+
+void     gtk_style_properties_unset_property (GtkStyleProperties *props,
+                                              const gchar        *property,
+                                              GtkStateFlags       state);
+
+void     gtk_style_properties_clear          (GtkStyleProperties  *props);
+
+void     gtk_style_properties_merge          (GtkStyleProperties       *props,
+                                              const GtkStyleProperties *props_to_merge,
+                                              gboolean                  replace);
+
+gboolean gtk_symbolic_color_resolve (GtkSymbolicColor    *color,
+                                    GtkStyleProperties  *props,
+                                     GdkRGBA             *resolved_color);
+gboolean gtk_gradient_resolve (GtkGradient         *gradient,
+                               GtkStyleProperties  *props,
+                               cairo_pattern_t    **resolved_gradient);
+
+G_END_DECLS
+
+#endif /* __GTK_STYLE_PROPERTIES_H__ */
index 2a9d2fc5e5ab3e4bf3c79cedeb05c2562f92d2ad..0f1312f34fbc8e5e35bed63cfa29640faa9f3508 100644 (file)
@@ -62,11 +62,11 @@ gtk_style_provider_iface_init (gpointer g_iface)
  * Returns the style settings affecting a widget defined by @path, or %NULL if
  * @provider doesn't contemplate styling @path.
  *
- * Returns: a #GtkStyleSet containing the style settings affecting @path
+ * Returns: a #GtkStyleProperties containing the style settings affecting @path
  *
  * Since: 3.0
  **/
-GtkStyleSet *
+GtkStyleProperties *
 gtk_style_provider_get_style (GtkStyleProvider *provider,
                               GtkWidgetPath    *path)
 {
index 0f763a2b412aa332171374fa58b775e38a8caa28..9e67a3286dbb84863b04580f086cd111b4871cc2 100644 (file)
@@ -23,7 +23,7 @@
 #include <glib-object.h>
 #include "gtkwidgetpath.h"
 #include "gtkiconfactory.h"
-#include "gtkstyleset.h"
+#include "gtkstyleproperties.h"
 #include "gtkenums.h"
 
 G_BEGIN_DECLS
@@ -52,8 +52,8 @@ struct _GtkStyleProviderIface
 {
   GTypeInterface g_iface;
 
-  GtkStyleSet * (* get_style) (GtkStyleProvider *provider,
-                               GtkWidgetPath    *path);
+  GtkStyleProperties * (* get_style) (GtkStyleProvider *provider,
+                                      GtkWidgetPath    *path);
 
   gboolean (* get_style_property) (GtkStyleProvider *provider,
                                    GtkWidgetPath    *path,
@@ -66,8 +66,8 @@ struct _GtkStyleProviderIface
 
 GType gtk_style_provider_get_type (void) G_GNUC_CONST;
 
-GtkStyleSet *gtk_style_provider_get_style (GtkStyleProvider *provider,
-                                           GtkWidgetPath    *path);
+GtkStyleProperties *gtk_style_provider_get_style (GtkStyleProvider *provider,
+                                                  GtkWidgetPath    *path);
 
 gboolean gtk_style_provider_get_style_property (GtkStyleProvider *provider,
                                                 GtkWidgetPath    *path,
diff --git a/gtk/gtkstyleset.c b/gtk/gtkstyleset.c
deleted file mode 100644 (file)
index e856d29..0000000
+++ /dev/null
@@ -1,1076 +0,0 @@
-/* GTK - The GIMP Toolkit
- * Copyright (C) 2010 Carlos Garnacho <carlosg@gnome.org>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
- */
-
-#include "config.h"
-
-#include <stdlib.h>
-#include <gobject/gvaluecollector.h>
-#include <cairo/cairo-gobject.h>
-
-#include "gtktypebuiltins.h"
-#include "gtkstyleprovider.h"
-#include "gtkstyleset.h"
-#include "gtkprivate.h"
-#include "gtkthemingengine.h"
-#include "gtkanimationdescription.h"
-#include "gtk9slice.h"
-#include "gtkintl.h"
-
-typedef struct GtkStyleSetPrivate GtkStyleSetPrivate;
-typedef struct PropertyData PropertyData;
-typedef struct PropertyNode PropertyNode;
-typedef struct ValueData ValueData;
-
-struct PropertyNode
-{
-  GQuark property_quark;
-  GType property_type;
-  GValue default_value;
-  GtkStylePropertyParser parse_func;
-};
-
-struct ValueData
-{
-  GtkStateFlags state;
-  GValue value;
-};
-
-struct PropertyData
-{
-  GArray *values;
-};
-
-struct GtkStyleSetPrivate
-{
-  GHashTable *color_map;
-  GHashTable *properties;
-};
-
-static GArray *properties = NULL;
-
-static void gtk_style_set_provider_init (GtkStyleProviderIface *iface);
-static void gtk_style_set_finalize      (GObject      *object);
-
-
-G_DEFINE_TYPE_EXTENDED (GtkStyleSet, gtk_style_set, G_TYPE_OBJECT, 0,
-                        G_IMPLEMENT_INTERFACE (GTK_TYPE_STYLE_PROVIDER,
-                                               gtk_style_set_provider_init));
-
-static void
-gtk_style_set_class_init (GtkStyleSetClass *klass)
-{
-  GObjectClass *object_class = G_OBJECT_CLASS (klass);
-  GValue val = { 0 };
-
-  object_class->finalize = gtk_style_set_finalize;
-
-  /* Initialize default property set */
-  gtk_style_set_register_property ("color", GDK_TYPE_RGBA, NULL, NULL);
-  gtk_style_set_register_property ("background-color", GDK_TYPE_RGBA, NULL, NULL);
-
-  gtk_style_set_register_property ("font", PANGO_TYPE_FONT_DESCRIPTION, NULL, NULL);
-
-  gtk_style_set_register_property ("margin", GTK_TYPE_BORDER, NULL, NULL);
-  gtk_style_set_register_property ("padding", GTK_TYPE_BORDER, NULL, NULL);
-
-  gtk_style_set_register_property ("border-width", G_TYPE_INT, NULL, NULL);
-  gtk_style_set_register_property ("border-radius", G_TYPE_INT, NULL, NULL);
-  gtk_style_set_register_property ("border-style", GTK_TYPE_BORDER_STYLE, NULL, NULL);
-  gtk_style_set_register_property ("border-color", GDK_TYPE_RGBA, NULL, NULL);
-
-  gtk_style_set_register_property ("background-image", CAIRO_GOBJECT_TYPE_PATTERN, NULL, NULL);
-  gtk_style_set_register_property ("border-image", GTK_TYPE_9SLICE, NULL, NULL);
-
-  g_value_init (&val, GTK_TYPE_THEMING_ENGINE);
-  g_value_set_object (&val, (GObject *) gtk_theming_engine_load (NULL));
-  gtk_style_set_register_property ("engine", GTK_TYPE_THEMING_ENGINE, &val, NULL);
-  g_value_unset (&val);
-
-  g_value_init (&val, GTK_TYPE_ANIMATION_DESCRIPTION);
-  g_value_take_boxed (&val, gtk_animation_description_new (0, GTK_TIMELINE_PROGRESS_LINEAR));
-  gtk_style_set_register_property ("transition", GTK_TYPE_ANIMATION_DESCRIPTION, &val, NULL);
-  g_value_unset (&val);
-
-  g_type_class_add_private (object_class, sizeof (GtkStyleSetPrivate));
-}
-
-static PropertyData *
-property_data_new (void)
-{
-  PropertyData *data;
-
-  data = g_slice_new0 (PropertyData);
-  data->values = g_array_new (FALSE, FALSE, sizeof (ValueData));
-
-  return data;
-}
-
-static void
-property_data_free (PropertyData *data)
-{
-  guint i;
-
-  for (i = 0; i < data->values->len; i++)
-    {
-      ValueData *value_data;
-
-      value_data = &g_array_index (data->values, ValueData, i);
-
-      if (G_IS_VALUE (&value_data->value))
-        g_value_unset (&value_data->value);
-    }
-
-  g_array_free (data->values, TRUE);
-  g_slice_free (PropertyData, data);
-}
-
-static gboolean
-property_data_find_position (PropertyData  *data,
-                             GtkStateFlags  state,
-                             guint         *pos)
-{
-  gint min, max, mid;
-  gboolean found = FALSE;
-  guint position;
-
-  if (pos)
-    *pos = 0;
-
-  if (data->values->len == 0)
-    return FALSE;
-
-  /* Find position for the given state, or the position where
-   * it would be if not found, the array is ordered by the
-   * state flags.
-   */
-  min = 0;
-  max = data->values->len - 1;
-
-  do
-    {
-      ValueData *value_data;
-
-      mid = (min + max) / 2;
-      value_data = &g_array_index (data->values, ValueData, mid);
-
-      if (value_data->state == state)
-        {
-          found = TRUE;
-          position = mid;
-        }
-      else if (value_data->state < state)
-          position = min = mid + 1;
-      else
-        {
-          max = mid - 1;
-          position = mid;
-        }
-    }
-  while (!found && min <= max);
-
-  if (pos)
-    *pos = position;
-
-  return found;
-}
-
-static GValue *
-property_data_get_value (PropertyData  *data,
-                         GtkStateFlags  state)
-{
-  ValueData *val_data;
-  guint pos;
-
-  if (!property_data_find_position (data, state, &pos))
-    {
-      ValueData new = { 0 };
-
-      //val_data = &g_array_index (data->values, ValueData, pos);
-      new.state = state;
-      g_array_insert_val (data->values, pos, new);
-    }
-
-  val_data = &g_array_index (data->values, ValueData, pos);
-
-  return &val_data->value;
-}
-
-static GValue *
-property_data_match_state (PropertyData  *data,
-                           GtkStateFlags  state)
-{
-  guint pos;
-  gint i;
-
-  if (property_data_find_position (data, state, &pos))
-    {
-      ValueData *val_data;
-
-      /* Exact match */
-      val_data = &g_array_index (data->values, ValueData, pos);
-      return &val_data->value;
-    }
-
-  if (pos >= data->values->len)
-    pos = data->values->len - 1;
-
-  /* No exact match, go downwards the list to find
-   * the closest match to the given state flags, as
-   * a side effect, there is an implicit precedence
-   * of higher flags over the smaller ones.
-   */
-  for (i = pos; i >= 0; i--)
-    {
-      ValueData *val_data;
-
-      val_data = &g_array_index (data->values, ValueData, i);
-
-       /* Check whether any of the requested
-        * flags are set, and no other flags are.
-        *
-        * Also, no flags acts as a wildcard, such
-        * value should be always in the first position
-        * in the array (if present) anyways.
-        */
-      if (val_data->state == 0 ||
-          ((val_data->state & state) != 0 &&
-           (val_data->state & ~state) == 0))
-        return &val_data->value;
-    }
-
-  return NULL;
-}
-
-static void
-gtk_style_set_init (GtkStyleSet *set)
-{
-  GtkStyleSetPrivate *priv;
-
-  priv = set->priv = G_TYPE_INSTANCE_GET_PRIVATE (set,
-                                                  GTK_TYPE_STYLE_SET,
-                                                  GtkStyleSetPrivate);
-
-  priv->properties = g_hash_table_new_full (NULL, NULL, NULL,
-                                            (GDestroyNotify) property_data_free);
-}
-
-static void
-gtk_style_set_finalize (GObject *object)
-{
-  GtkStyleSetPrivate *priv;
-  GtkStyleSet *set;
-
-  set = GTK_STYLE_SET (object);
-  priv = set->priv;
-  g_hash_table_destroy (priv->properties);
-
-  if (priv->color_map)
-    g_hash_table_destroy (priv->color_map);
-
-  G_OBJECT_CLASS (gtk_style_set_parent_class)->finalize (object);
-}
-
-GtkStyleSet *
-gtk_style_set_get_style (GtkStyleProvider *provider,
-                         GtkWidgetPath    *path)
-{
-  /* Return style set itself */
-  return g_object_ref (provider);
-}
-
-static void
-gtk_style_set_provider_init (GtkStyleProviderIface *iface)
-{
-  iface->get_style = gtk_style_set_get_style;
-}
-
-static int
-compare_property (gconstpointer p1,
-                  gconstpointer p2)
-{
-  PropertyNode *key = (PropertyNode *) p1;
-  PropertyNode *node = (PropertyNode *) p2;
-
-  if (key->property_quark > node->property_quark)
-    return 1;
-  else if (key->property_quark < node->property_quark)
-    return -1;
-
-  return 0;
-}
-
-static PropertyNode *
-property_node_lookup (GQuark quark)
-{
-  PropertyNode key = { 0 };
-
-  if (!quark)
-    return NULL;
-
-  if (!properties)
-    return NULL;
-
-  key.property_quark = quark;
-
-  return bsearch (&key, properties->data, properties->len,
-                  sizeof (PropertyNode), compare_property);
-}
-
-/* Property registration functions */
-
-/**
- * gtk_style_set_register_property:
- * @property_name: property name to register
- * @type: #GType the property will hold
- * @default_value: default value for this property
- * @parse_func: parsing function to use, or %NULL
- *
- * Registers a property so it can be used in the CSS file format.
- * This function is the low-level equivalent of
- * gtk_theming_engine_register_property(), if you are implementing
- * a theming engine, you want to use that function instead.
- *
- * Since: 3.0
- **/
-void
-gtk_style_set_register_property (const gchar            *property_name,
-                                 GType                   type,
-                                 const GValue           *default_value,
-                                 GtkStylePropertyParser  parse_func)
-{
-  PropertyNode *node, new = { 0 };
-  GQuark quark;
-  gint i;
-
-  g_return_if_fail (property_name != NULL);
-  g_return_if_fail (type != 0);
-
-  if (G_UNLIKELY (!properties))
-    properties = g_array_new (FALSE, TRUE, sizeof (PropertyNode));
-
-  quark = g_quark_try_string (property_name);
-
-  if ((node = property_node_lookup (quark)) != NULL)
-    {
-      g_warning ("Property \"%s\" was already registered with type %s",
-                 property_name, g_type_name (node->property_type));
-      return;
-    }
-
-  quark = g_quark_from_string (property_name);
-
-  new.property_quark = quark;
-  new.property_type = type;
-
-  if (default_value)
-    {
-      g_value_init (&new.default_value, G_VALUE_TYPE (default_value));
-      g_value_copy (default_value, &new.default_value);
-    }
-  else
-    g_value_init (&new.default_value, type);
-
-  if (parse_func)
-    new.parse_func = parse_func;
-
-  for (i = 0; i < properties->len; i++)
-    {
-      node = &g_array_index (properties, PropertyNode, i);
-
-      if (node->property_quark > quark)
-        break;
-    }
-
-  g_array_insert_val (properties, i, new);
-}
-
-/**
- * gtk_style_set_lookup_property:
- * @property_name: property name to look up
- * @type: (out): return location for the looked up property type
- * @parse_func: (out): return value for the parse function
- *
- * Returns %TRUE if a property has been registered, if @type or
- * @parse_func are not %NULL, the property #GType and parsing function
- * will be respectively returned.
- *
- * Returns: %TRUE if the property is registered, %FALSE otherwise
- *
- * Since: 3.0
- **/
-gboolean
-gtk_style_set_lookup_property (const gchar            *property_name,
-                               GType                  *type,
-                               GtkStylePropertyParser *parse_func)
-{
-  PropertyNode *node;
-  GtkStyleSetClass *klass;
-  gboolean found = FALSE;
-  GQuark quark;
-  gint i;
-
-  g_return_val_if_fail (property_name != NULL, FALSE);
-
-  klass = g_type_class_ref (GTK_TYPE_STYLE_SET);
-  quark = g_quark_try_string (property_name);
-
-  if (quark == 0)
-    {
-      g_type_class_unref (klass);
-      return FALSE;
-    }
-
-  for (i = 0; i < properties->len; i++)
-    {
-      node = &g_array_index (properties, PropertyNode, i);
-
-      if (node->property_quark == quark)
-        {
-          if (type)
-            *type = node->property_type;
-
-          if (parse_func)
-            *parse_func = node->parse_func;
-
-          found = TRUE;
-          break;
-        }
-      else if (node->property_quark > quark)
-        break;
-    }
-
-  g_type_class_unref (klass);
-
-  return found;
-}
-
-/* GtkStyleSet methods */
-
-/**
- * gtk_style_set_new:
- *
- * Returns a newly created #GtkStyleSet
- *
- * Returns: a new #GtkStyleSet
- **/
-GtkStyleSet *
-gtk_style_set_new (void)
-{
-  return g_object_new (GTK_TYPE_STYLE_SET, NULL);
-}
-
-/**
- * gtk_style_set_map_color:
- * @set: a #GtkStyleSet
- * @name: color name
- * @color: #GtkSymbolicColor to map @name to
- *
- * Maps @color so it can be referenced by @name. See
- * gtk_style_set_lookup_color()
- *
- * Since: 3.0
- **/
-void
-gtk_style_set_map_color (GtkStyleSet      *set,
-                        const gchar      *name,
-                        GtkSymbolicColor *color)
-{
-  GtkStyleSetPrivate *priv;
-
-  g_return_if_fail (GTK_IS_STYLE_SET (set));
-  g_return_if_fail (name != NULL);
-  g_return_if_fail (color != NULL);
-
-  priv = set->priv;
-
-  if (G_UNLIKELY (!priv->color_map))
-    priv->color_map = g_hash_table_new_full (g_str_hash,
-                                             g_str_equal,
-                                             (GDestroyNotify) g_free,
-                                             (GDestroyNotify) gtk_symbolic_color_unref);
-
-  g_hash_table_replace (priv->color_map,
-                        g_strdup (name),
-                        gtk_symbolic_color_ref (color));
-}
-
-/**
- * gtk_style_set_lookup_color:
- * @set: a #GtkStyleSet
- * @name: color name to lookup
- *
- * Returns the symbolic color that is mapped
- * to @name.
- *
- * Returns: The mapped color
- *
- * Since: 3.0
- **/
-GtkSymbolicColor *
-gtk_style_set_lookup_color (GtkStyleSet *set,
-                           const gchar *name)
-{
-  GtkStyleSetPrivate *priv;
-
-  g_return_val_if_fail (GTK_IS_STYLE_SET (set), NULL);
-  g_return_val_if_fail (name != NULL, NULL);
-
-  priv = set->priv;
-
-  if (!priv->color_map)
-    return NULL;
-
-  return g_hash_table_lookup (priv->color_map, name);
-}
-
-/**
- * gtk_style_set_set_property:
- * @set: a #GtkStyleSet
- * @property: styling property to set
- * @state: state to set the value for
- * @value: new value for the property
- *
- * Sets a styling property in @set.
- *
- * Since: 3.0
- **/
-void
-gtk_style_set_set_property (GtkStyleSet   *set,
-                            const gchar   *property,
-                            GtkStateFlags  state,
-                            const GValue  *value)
-{
-  GtkStyleSetPrivate *priv;
-  PropertyNode *node;
-  PropertyData *prop;
-  GType value_type;
-  GValue *val;
-
-  g_return_if_fail (GTK_IS_STYLE_SET (set));
-  g_return_if_fail (property != NULL);
-  g_return_if_fail (value != NULL);
-
-  value_type = G_VALUE_TYPE (value);
-  node = property_node_lookup (g_quark_try_string (property));
-
-  if (!node)
-    {
-      g_warning ("Style property \"%s\" is not registered", property);
-      return;
-    }
-
-  if (node->property_type == GDK_TYPE_RGBA)
-    {
-      /* Allow GtkSymbolicColor as well */
-      g_return_if_fail (value_type == GDK_TYPE_RGBA || value_type == GTK_TYPE_SYMBOLIC_COLOR);
-    }
-  else if (node->property_type == CAIRO_GOBJECT_TYPE_PATTERN)
-    {
-      /* Allow GtkGradient as a substitute */
-      g_return_if_fail (value_type == CAIRO_GOBJECT_TYPE_PATTERN ||
-                        value_type == GTK_TYPE_GRADIENT);
-    }
-  else
-    g_return_if_fail (node->property_type == value_type);
-
-  priv = set->priv;
-  prop = g_hash_table_lookup (priv->properties,
-                              GINT_TO_POINTER (node->property_quark));
-
-  if (!prop)
-    {
-      prop = property_data_new ();
-      g_hash_table_insert (priv->properties,
-                           GINT_TO_POINTER (node->property_quark),
-                           prop);
-    }
-
-  val = property_data_get_value (prop, state);
-
-  if (G_VALUE_TYPE (val) == value_type)
-    g_value_reset (val);
-  else
-    {
-      if (G_IS_VALUE (val))
-        g_value_unset (val);
-
-      g_value_init (val, value_type);
-    }
-
-  g_value_copy (value, val);
-}
-
-/**
- * gtk_style_set_set_valist:
- * @set: a #GtkStyleSet
- * @state: state to set the values for
- * @args: va_list of property name/value pairs, followed by %NULL
- *
- * Sets several style properties on @set.
- *
- * Since: 3.0
- **/
-void
-gtk_style_set_set_valist (GtkStyleSet   *set,
-                          GtkStateFlags  state,
-                          va_list        args)
-{
-  GtkStyleSetPrivate *priv;
-  const gchar *property_name;
-
-  g_return_if_fail (GTK_IS_STYLE_SET (set));
-
-  priv = set->priv;
-  property_name = va_arg (args, const gchar *);
-
-  while (property_name)
-    {
-      PropertyNode *node;
-      PropertyData *prop;
-      gchar *error = NULL;
-      GValue *val;
-
-      node = property_node_lookup (g_quark_try_string (property_name));
-
-      if (!node)
-        {
-          g_warning ("Style property \"%s\" is not registered", property_name);
-          break;
-        }
-
-      prop = g_hash_table_lookup (priv->properties,
-                                  GINT_TO_POINTER (node->property_quark));
-
-      if (!prop)
-        {
-          prop = property_data_new ();
-          g_hash_table_insert (priv->properties,
-                               GINT_TO_POINTER (node->property_quark),
-                               prop);
-        }
-
-      val = property_data_get_value (prop, state);
-
-      if (G_IS_VALUE (val))
-        g_value_unset (val);
-
-      g_value_init (val, node->property_type);
-      G_VALUE_COLLECT (val, args, 0, &error);
-
-      if (error)
-        {
-          g_warning ("Could not set style property \"%s\": %s", property_name, error);
-          g_value_unset (val);
-          g_free (error);
-          break;
-        }
-
-      property_name = va_arg (args, const gchar *);
-    }
-}
-
-/**
- * gtk_style_set_set:
- * @set: a #GtkStyleSet
- * @state: state to set the values for
- * @...: property name/value pairs, followed by %NULL
- *
- * Sets several style properties on @set.
- *
- * Since: 3.0
- **/
-void
-gtk_style_set_set (GtkStyleSet   *set,
-                   GtkStateFlags  state,
-                   ...)
-{
-  va_list args;
-
-  g_return_if_fail (GTK_IS_STYLE_SET (set));
-
-  va_start (args, state);
-  gtk_style_set_set_valist (set, state, args);
-  va_end (args);
-}
-
-static gboolean
-resolve_color (GtkStyleSet *set,
-              GValue      *value)
-{
-  GdkRGBA color;
-
-  /* Resolve symbolic color to GdkRGBA */
-  if (!gtk_symbolic_color_resolve (g_value_get_boxed (value), set, &color))
-    return FALSE;
-
-  /* Store it back, this is where GdkRGBA caching happens */
-  g_value_unset (value);
-  g_value_init (value, GDK_TYPE_RGBA);
-  g_value_set_boxed (value, &color);
-
-  return TRUE;
-}
-
-static gboolean
-resolve_gradient (GtkStyleSet *set,
-                  GValue      *value)
-{
-  cairo_pattern_t *gradient;
-
-  if (!gtk_gradient_resolve (g_value_get_boxed (value), set, &gradient))
-    return FALSE;
-
-  /* Store it back, this is where cairo_pattern_t caching happens */
-  g_value_unset (value);
-  g_value_init (value, CAIRO_GOBJECT_TYPE_PATTERN);
-  g_value_take_boxed (value, gradient);
-
-  return TRUE;
-}
-
-/**
- * gtk_style_set_get_property:
- * @set: a #GtkStyleSet
- * @property: style property name
- * @state: state to retrieve the property value for
- * @value: (out) (transfer full):  return location for the style property value.
- *
- * Gets a style property from @set for the given state. When done with @value,
- * g_value_unset() needs to be called to free any allocated memory.
- *
- * Returns: %TRUE if the property exists in @set, %FALSE otherwise
- *
- * Since: 3.0
- **/
-gboolean
-gtk_style_set_get_property (GtkStyleSet   *set,
-                            const gchar   *property,
-                            GtkStateFlags  state,
-                            GValue        *value)
-{
-  GtkStyleSetPrivate *priv;
-  PropertyNode *node;
-  PropertyData *prop;
-  GValue *val;
-
-  g_return_val_if_fail (GTK_IS_STYLE_SET (set), FALSE);
-  g_return_val_if_fail (property != NULL, FALSE);
-  g_return_val_if_fail (value != NULL, FALSE);
-
-  node = property_node_lookup (g_quark_try_string (property));
-
-  if (!node)
-    {
-      g_warning ("Style property \"%s\" is not registered", property);
-      return FALSE;
-    }
-
-  priv = set->priv;
-  prop = g_hash_table_lookup (priv->properties,
-                              GINT_TO_POINTER (node->property_quark));
-
-  if (!prop)
-    return FALSE;
-
-  g_value_init (value, node->property_type);
-
-  val = property_data_match_state (prop, state);
-
-  if (!val)
-    val = &node->default_value;
-
-  g_return_val_if_fail (G_IS_VALUE (val), FALSE);
-
-  if (G_VALUE_TYPE (val) == GTK_TYPE_SYMBOLIC_COLOR)
-    {
-      g_return_val_if_fail (node->property_type == GDK_TYPE_RGBA, FALSE);
-
-      if (!resolve_color (set, val))
-        return FALSE;
-    }
-  else if (G_VALUE_TYPE (val) == GTK_TYPE_GRADIENT)
-    {
-      g_return_val_if_fail (node->property_type == CAIRO_GOBJECT_TYPE_PATTERN, FALSE);
-
-      if (!resolve_gradient (set, val))
-        return FALSE;
-    }
-
-  g_value_copy (val, value);
-
-  return TRUE;
-}
-
-/**
- * gtk_style_set_get_valist:
- * @set: a #GtkStyleSet
- * @state: state to retrieve the property values for
- * @args: va_list of property name/return location pairs, followed by %NULL
- *
- * Retrieves several style property values from @set for a given state.
- *
- * Since: 3.0
- **/
-void
-gtk_style_set_get_valist (GtkStyleSet   *set,
-                          GtkStateFlags  state,
-                          va_list        args)
-{
-  GtkStyleSetPrivate *priv;
-  const gchar *property_name;
-
-  g_return_if_fail (GTK_IS_STYLE_SET (set));
-
-  priv = set->priv;
-  property_name = va_arg (args, const gchar *);
-
-  while (property_name)
-    {
-      PropertyNode *node;
-      PropertyData *prop;
-      gchar *error = NULL;
-      GValue *val = NULL;
-
-      node = property_node_lookup (g_quark_try_string (property_name));
-
-      if (!node)
-        {
-          g_warning ("Style property \"%s\" is not registered", property_name);
-          break;
-        }
-
-      prop = g_hash_table_lookup (priv->properties,
-                                  GINT_TO_POINTER (node->property_quark));
-
-      if (prop)
-        val = property_data_match_state (prop, state);
-
-      if (!val)
-        val = &node->default_value;
-
-      if (G_VALUE_TYPE (val) == GTK_TYPE_SYMBOLIC_COLOR)
-        {
-          g_return_if_fail (node->property_type == GDK_TYPE_RGBA);
-
-          if (!resolve_color (set, val))
-            val = &node->default_value;
-        }
-      else if (G_VALUE_TYPE (val) == GTK_TYPE_GRADIENT)
-        {
-          g_return_if_fail (node->property_type == CAIRO_GOBJECT_TYPE_PATTERN);
-
-          if (!resolve_gradient (set, val))
-            val = &node->default_value;
-        }
-
-      G_VALUE_LCOPY (val, args, 0, &error);
-
-      if (error)
-        {
-          g_warning ("Could not get style property \"%s\": %s", property_name, error);
-          g_free (error);
-          break;
-        }
-
-      property_name = va_arg (args, const gchar *);
-    }
-}
-
-/**
- * gtk_style_set_get:
- * @set: a #GtkStyleSet
- * @state: state to retrieve the property values for
- * @...: property name /return value pairs, followed by %NULL
- *
- * Retrieves several style property values from @set for a
- * given state.
- *
- * Since: 3.0
- **/
-void
-gtk_style_set_get (GtkStyleSet   *set,
-                   GtkStateFlags  state,
-                   ...)
-{
-  va_list args;
-
-  g_return_if_fail (GTK_IS_STYLE_SET (set));
-
-  va_start (args, state);
-  gtk_style_set_get_valist (set, state, args);
-  va_end (args);
-}
-
-/**
- * gtk_style_set_unset_property:
- * @set: a #GtkStyleSet
- * @property: property to unset
- * @state: state to unset
- *
- * Unsets a style property in @set.
- *
- * Since: 3.0
- **/
-void
-gtk_style_set_unset_property (GtkStyleSet   *set,
-                              const gchar   *property,
-                              GtkStateFlags  state)
-{
-  GtkStyleSetPrivate *priv;
-  PropertyNode *node;
-  PropertyData *prop;
-  guint pos;
-
-  g_return_if_fail (GTK_IS_STYLE_SET (set));
-  g_return_if_fail (property != NULL);
-
-  node = property_node_lookup (g_quark_try_string (property));
-
-  if (!node)
-    {
-      g_warning ("Style property \"%s\" is not registered", property);
-      return;
-    }
-
-  priv = set->priv;
-  prop = g_hash_table_lookup (priv->properties,
-                              GINT_TO_POINTER (node->property_quark));
-
-  if (!prop)
-    return;
-
-  if (property_data_find_position (prop, state, &pos))
-    {
-      ValueData *data;
-
-      data = &g_array_index (prop->values, ValueData, pos);
-
-      if (G_IS_VALUE (&data->value))
-        g_value_unset (&data->value);
-
-      g_array_remove_index (prop->values, pos);
-    }
-}
-
-/**
- * gtk_style_set_clear:
- * @set: a #GtkStyleSet
- *
- * Clears all style information from @set.
- **/
-void
-gtk_style_set_clear (GtkStyleSet *set)
-{
-  GtkStyleSetPrivate *priv;
-
-  g_return_if_fail (GTK_IS_STYLE_SET (set));
-
-  priv = set->priv;
-  g_hash_table_remove_all (priv->properties);
-}
-
-/**
- * gtk_style_set_merge:
- * @set: a #GtkStyleSet
- * @set_to_merge: a second #GtkStyleSet
- * @replace: whether to replace values or not
- *
- * Merges into @set all the style information contained
- * in @set_to_merge. If @replace is %TRUE, the values
- * will be overwritten, if it is %FALSE, the older values
- * will prevail.
- *
- * Since: 3.0
- **/
-void
-gtk_style_set_merge (GtkStyleSet       *set,
-                     const GtkStyleSet *set_to_merge,
-                     gboolean           replace)
-{
-  GtkStyleSetPrivate *priv, *priv_to_merge;
-  GHashTableIter iter;
-  gpointer key, value;
-
-  g_return_if_fail (GTK_IS_STYLE_SET (set));
-  g_return_if_fail (GTK_IS_STYLE_SET (set_to_merge));
-
-  priv = set->priv;
-  priv_to_merge = set_to_merge->priv;
-
-  /* Merge symbolic color map */
-  if (priv_to_merge->color_map)
-    {
-      g_hash_table_iter_init (&iter, priv_to_merge->color_map);
-
-      while (g_hash_table_iter_next (&iter, &key, &value))
-        {
-          const gchar *name;
-          GtkSymbolicColor *color;
-
-          name = key;
-          color = value;
-
-          if (!replace &&
-              g_hash_table_lookup (priv->color_map, name))
-            continue;
-
-          gtk_style_set_map_color (set, name, color);
-        }
-    }
-
-  /* Merge symbolic style properties */
-  g_hash_table_iter_init (&iter, priv_to_merge->properties);
-
-  while (g_hash_table_iter_next (&iter, &key, &value))
-    {
-      PropertyData *prop_to_merge = value;
-      PropertyData *prop;
-      guint i;
-
-      prop = g_hash_table_lookup (priv->properties, key);
-
-      if (!prop)
-        {
-          prop = property_data_new ();
-          g_hash_table_insert (priv->properties, key, prop);
-        }
-
-      for (i = 0; i < prop_to_merge->values->len; i++)
-        {
-          ValueData *data;
-          GValue *value;
-
-          data = &g_array_index (prop_to_merge->values, ValueData, i);
-          value = property_data_get_value (prop, data->state);
-
-          if (replace || !G_IS_VALUE (value))
-            {
-              if (!G_IS_VALUE (value))
-                g_value_init (value, G_VALUE_TYPE (&data->value));
-              else if (G_VALUE_TYPE (value) != G_VALUE_TYPE (&data->value))
-                {
-                  g_value_unset (value);
-                  g_value_init (value, G_VALUE_TYPE (&data->value));
-                }
-
-              g_value_copy (&data->value, value);
-            }
-        }
-    }
-}
diff --git a/gtk/gtkstyleset.h b/gtk/gtkstyleset.h
deleted file mode 100644 (file)
index 60544ad..0000000
+++ /dev/null
@@ -1,115 +0,0 @@
-/* GTK - The GIMP Toolkit
- * Copyright (C) 2010 Carlos Garnacho <carlosg@gnome.org>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
- */
-
-#ifndef __GTK_STYLE_SET_H__
-#define __GTK_STYLE_SET_H__
-
-#include <glib-object.h>
-#include <gdk/gdk.h>
-#include "gtkenums.h"
-#include "gtksymboliccolor.h"
-
-G_BEGIN_DECLS
-
-#define GTK_TYPE_STYLE_SET         (gtk_style_set_get_type ())
-#define GTK_STYLE_SET(o)           (G_TYPE_CHECK_INSTANCE_CAST ((o), GTK_TYPE_STYLE_SET, GtkStyleSet))
-#define GTK_STYLE_SET_CLASS(c)     (G_TYPE_CHECK_CLASS_CAST    ((c), GTK_TYPE_STYLE_SET, GtkStyleSetClass))
-#define GTK_IS_STYLE_SET(o)        (G_TYPE_CHECK_INSTANCE_TYPE ((o), GTK_TYPE_STYLE_SET))
-#define GTK_IS_STYLE_SET_CLASS(c)  (G_TYPE_CHECK_CLASS_TYPE    ((c), GTK_TYPE_STYLE_SET))
-#define GTK_STYLE_SET_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS  ((o), GTK_TYPE_STYLE_SET, GtkStyleSetClass))
-
-typedef struct _GtkStyleSet GtkStyleSet;
-typedef struct _GtkStyleSetClass GtkStyleSetClass;
-
-struct _GtkStyleSet
-{
-  GObject parent_object;
-  gpointer priv;
-};
-
-struct _GtkStyleSetClass
-{
-  GObjectClass parent_class;
-};
-
-typedef gboolean (* GtkStylePropertyParser) (const gchar  *string,
-                                             GValue       *value,
-                                             GError      **error);
-
-GType gtk_style_set_get_type (void) G_GNUC_CONST;
-
-/* Functions to register style properties */
-void     gtk_style_set_register_property (const gchar            *property_name,
-                                          GType                   type,
-                                          const GValue           *default_value,
-                                          GtkStylePropertyParser  parse_func);
-gboolean gtk_style_set_lookup_property   (const gchar            *property_name,
-                                          GType                  *type,
-                                          GtkStylePropertyParser *parse_func);
-
-GtkStyleSet * gtk_style_set_new (void);
-
-void               gtk_style_set_map_color    (GtkStyleSet      *set,
-                                               const gchar      *name,
-                                               GtkSymbolicColor *color);
-GtkSymbolicColor * gtk_style_set_lookup_color (GtkStyleSet *set,
-                                               const gchar *name);
-
-void     gtk_style_set_set_property (GtkStyleSet   *set,
-                                     const gchar   *property,
-                                     GtkStateFlags  state,
-                                     const GValue  *value);
-void     gtk_style_set_set_valist   (GtkStyleSet   *set,
-                                     GtkStateFlags  state,
-                                     va_list        args);
-void     gtk_style_set_set          (GtkStyleSet   *set,
-                                     GtkStateFlags  state,
-                                     ...) G_GNUC_NULL_TERMINATED;
-
-gboolean gtk_style_set_get_property (GtkStyleSet   *set,
-                                     const gchar   *property,
-                                     GtkStateFlags  state,
-                                     GValue        *value);
-void     gtk_style_set_get_valist   (GtkStyleSet   *set,
-                                     GtkStateFlags  state,
-                                     va_list        args);
-void     gtk_style_set_get          (GtkStyleSet   *set,
-                                     GtkStateFlags  state,
-                                     ...) G_GNUC_NULL_TERMINATED;
-
-void     gtk_style_set_unset_property (GtkStyleSet   *set,
-                                       const gchar   *property,
-                                       GtkStateFlags  state);
-
-void     gtk_style_set_clear          (GtkStyleSet  *set);
-
-void     gtk_style_set_merge          (GtkStyleSet       *set,
-                                       const GtkStyleSet *set_to_merge,
-                                       gboolean           replace);
-
-gboolean gtk_symbolic_color_resolve (GtkSymbolicColor    *color,
-                                    GtkStyleSet         *style_set,
-                                     GdkRGBA             *resolved_color);
-gboolean gtk_gradient_resolve (GtkGradient      *gradient,
-                               GtkStyleSet      *style_set,
-                               cairo_pattern_t **resolved_gradient);
-
-G_END_DECLS
-
-#endif /* __GTK_STYLE_PROPERTY_SET_H__ */
index f45c8d2046d460ee4c612c125f798409791755ef..c37313d198eb9954a5043f06f25ba3a9c354b0b8 100644 (file)
@@ -19,7 +19,7 @@
 
 #include "config.h"
 #include "gtksymboliccolor.h"
-#include "gtkstyleset.h"
+#include "gtkstyleproperties.h"
 #include "gtkintl.h"
 
 G_DEFINE_BOXED_TYPE (GtkSymbolicColor, gtk_symbolic_color,
@@ -114,7 +114,7 @@ gtk_symbolic_color_new_literal (GdkRGBA *color)
  *
  * Creates a symbolic color pointing to an unresolved named
  * color. See gtk_style_context_lookup_color() and
- * gtk_style_set_lookup_color().
+ * gtk_style_properties_lookup_color().
  *
  * Returns: a newly created #GtkSymbolicColor
  *
@@ -295,25 +295,25 @@ gtk_symbolic_color_unref (GtkSymbolicColor *color)
 /**
  * gtk_symbolic_color_resolve:
  * @color: a #GtkSymbolicColor
- * @style_set: #GtkStyleSet to use when resolving named colors
+ * @props: #GtkStyleProperties to use when resolving named colors
  * @resolved_color: (out): return location for the resolved color
  *
  * If @color is resolvable, @resolved_color will be filled in
  * with the resolved color, and %TRUE will be returned. Generally,
  * if @color can't be resolved, it is due to it being defined on
- * top of a named color that doesn't exist in @style_set.
+ * top of a named color that doesn't exist in @props.
  *
  * Returns: %TRUE if the color has been resolved
  *
  * Since: 3.0
  **/
 gboolean
-gtk_symbolic_color_resolve (GtkSymbolicColor *color,
-                            GtkStyleSet      *style_set,
-                            GdkRGBA          *resolved_color)
+gtk_symbolic_color_resolve (GtkSymbolicColor   *color,
+                            GtkStyleProperties *props,
+                            GdkRGBA            *resolved_color)
 {
   g_return_val_if_fail (color != NULL, FALSE);
-  g_return_val_if_fail (GTK_IS_STYLE_SET (style_set), FALSE);
+  g_return_val_if_fail (GTK_IS_STYLE_PROPERTIES (props), FALSE);
   g_return_val_if_fail (resolved_color != NULL, FALSE);
 
   switch (color->type)
@@ -325,12 +325,12 @@ gtk_symbolic_color_resolve (GtkSymbolicColor *color,
       {
         GtkSymbolicColor *named_color;
 
-        named_color = gtk_style_set_lookup_color (style_set, color->name);
+        named_color = gtk_style_properties_lookup_color (props, color->name);
 
         if (!named_color)
           return FALSE;
 
-        return gtk_symbolic_color_resolve (named_color, style_set, resolved_color);
+        return gtk_symbolic_color_resolve (named_color, props, resolved_color);
       }
 
       break;
@@ -338,7 +338,7 @@ gtk_symbolic_color_resolve (GtkSymbolicColor *color,
       {
         GdkRGBA shade;
 
-        if (!gtk_symbolic_color_resolve (color->shade.color, style_set, &shade))
+        if (!gtk_symbolic_color_resolve (color->shade.color, props, &shade))
           return FALSE;
 
         resolved_color->red = CLAMP (shade.red * color->shade.factor, 0, 1);
@@ -354,7 +354,7 @@ gtk_symbolic_color_resolve (GtkSymbolicColor *color,
       {
         GdkRGBA alpha;
 
-        if (!gtk_symbolic_color_resolve (color->alpha.color, style_set, &alpha))
+        if (!gtk_symbolic_color_resolve (color->alpha.color, props, &alpha))
           return FALSE;
 
         *resolved_color = alpha;
@@ -366,10 +366,10 @@ gtk_symbolic_color_resolve (GtkSymbolicColor *color,
       {
         GdkRGBA color1, color2;
 
-        if (!gtk_symbolic_color_resolve (color->mix.color1, style_set, &color1))
+        if (!gtk_symbolic_color_resolve (color->mix.color1, props, &color1))
           return FALSE;
 
-        if (!gtk_symbolic_color_resolve (color->mix.color2, style_set, &color2))
+        if (!gtk_symbolic_color_resolve (color->mix.color2, props, &color2))
           return FALSE;
 
         resolved_color->red = CLAMP (color1.red + ((color2.red - color1.red) * color->mix.factor), 0, 1);
@@ -549,29 +549,29 @@ gtk_gradient_unref (GtkGradient *gradient)
 /**
  * gtk_gradient_resolve:
  * @gradient: a #GtkGradient
- * @style_set: #GtkStyleSet to use when resolving named colors
+ * @props: #GtkStyleProperties to use when resolving named colors
  * @resolved_gradient: (out): return location for the resolved pattern
  *
  * If @gradient is resolvable, @resolved_gradient will be filled in
  * with the resolved gradient as a cairo_pattern_t, and %TRUE will
  * be returned. Generally, if @gradient can't be resolved, it is
  * due to it being defined on top of a named color that doesn't
- * exist in @style_set.
+ * exist in @props.
  *
  * Returns: %TRUE if the gradient has been resolved
  *
  * Since: 3.0
  **/
 gboolean
-gtk_gradient_resolve (GtkGradient      *gradient,
-                      GtkStyleSet      *style_set,
-                      cairo_pattern_t **resolved_gradient)
+gtk_gradient_resolve (GtkGradient         *gradient,
+                      GtkStyleProperties  *props,
+                      cairo_pattern_t    **resolved_gradient)
 {
   cairo_pattern_t *pattern;
   guint i;
 
   g_return_val_if_fail (gradient != NULL, FALSE);
-  g_return_val_if_fail (GTK_IS_STYLE_SET (style_set), FALSE);
+  g_return_val_if_fail (GTK_IS_STYLE_PROPERTIES (props), FALSE);
   g_return_val_if_fail (resolved_gradient != NULL, FALSE);
 
   if (gradient->radius0 == 0 && gradient->radius1 == 0)
@@ -590,7 +590,7 @@ gtk_gradient_resolve (GtkGradient      *gradient,
 
       stop = &g_array_index (gradient->stops, ColorStop, i);
 
-      if (!gtk_symbolic_color_resolve (stop->color, style_set, &color))
+      if (!gtk_symbolic_color_resolve (stop->color, props, &color))
         {
           cairo_pattern_destroy (pattern);
           return FALSE;
index 5360ad0407ae1e9d1662c4cc86798151b4630035..ca3b3139f53a593d6f44a910c02681abf7b4c10a 100644 (file)
@@ -376,7 +376,7 @@ gtk_theming_engine_register_property (GtkThemingEngine       *engine,
     engine_name = G_OBJECT_TYPE_NAME (engine);
 
   name = g_strdup_printf ("-%s-%s", engine_name, property_name);
-  gtk_style_set_register_property (name, type, default_value, parse_func);
+  gtk_style_properties_register_property (name, type, default_value, parse_func);
   g_free (name);
 }